﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Linq;

namespace intelliSys.Management.Automation.Test
{
    public class ValidationLogic
    {
        public string Summary
        {
            get;
            set;
        }
        public delegate bool Validate(FrameworkElement fe);
        public Validate ValidateMethod;
        public FrameworkElement FrameworkElement
        {
            get;
            set;
        }
        public string Detail
        {
            get;
            set;
        }
        public bool PreventContinue
        {
            get;
            set;
        }
        public string ImgSrc
        {
            get
            {
                if (PreventContinue)
                {
                    return "Icons/error.png";
                }
                else
                {
                    return "Icons/warning.png";
                }
            }
        }
        public static bool Non_EmptyLogic(FrameworkElement fe)
        {
            return (fe as TextBox).Text != "";
        }
        public static bool Double01Range(FrameworkElement fe)
        {
            var text = (fe as TextBox).Text;
            double value;
            if (double.TryParse(text, out value))
            {
                if (value <= 1 && value >= 0)
                    return true;
                else
                    return false;
            }
            else
            {
                return false;
            }
        }
        public static bool UnCheckedNotice(FrameworkElement fe)
        {
            return (fe as CheckBox).IsChecked.Value;
        }
        public static bool NonSelectedLogic(FrameworkElement fe)
        {
            return (fe as ComboBox).SelectedItem != null;
        }
        public static bool ListBoxEmptyLogic(FrameworkElement fe)
        {
            return (fe as ListBox).Items.Count != 0;
        }
        public static bool DateTimeFormatLogic(FrameworkElement fe)
        {
            var text = (fe as TextBox).Text;
            DateTime dt;
            bool success = DateTime.TryParse(text, out dt);
            if (!success)
            {
                return false;
            }
            if (dt < DateTime.Parse("2000.1.1"))
            {
                return false;
            }
            return true;
        }
        public static bool IntValidityLogic(FrameworkElement fe)
        {
            var text = (fe as TextBox).Text;
            int result;
            if (int.TryParse(text, out result))
            {
                return true;
            }
            return false;
        }
    }
}
